import * as ajax from '@/api/api'
import { getOrgsStatusList } from '@/api/organization'

export default {
  async setUserInfo ({ state, commit }, payload) {
    let res = await ajax.getUserInfor(payload.parames)
    if (res.status === 200 && res.data) {
      commit('SET_USER_INFO', { info: res.data, isLogin: true, callback: payload.callBack })
    } else {
      commit('SET_USER_INFO', { info: null, isLogin: false, callback: payload.callBack })
    }
  },
  async requestLogin ({ state, commit }, payload) {
    let res = await ajax.requestLogin(payload)
    if (res.status === 200 && res.data) { // 登录成功dispatch
      commit('GET_USER_INFO', { info: res.data, isLogin: true })
    } else {
      commit('GET_USER_INFO', { info: res, isLogin: false })
    }
    return res
  },
  async setOrgList ({ state, commit }, payload) {
    let res = await getOrgsStatusList({
      orgIds:state.userInfo.organizationIds
    })
    if (res.status === 200 && res.data) {
      commit('setOrgList',res.data.orgDetail)
    }
  },
}
